***************************************
**** Figure A3 - Treatment Effects on Worker Productivity by Wealth Level
***************************************


use "$dir/Data/analysis_main.dta", clear



gen wealth1 = wealth_ind_avg<0.1 if !mi(wealth_ind_avg)
gen wealth2 = wealth_ind_avg>0 & wealth_ind_avg<0.5 if !mi(wealth_ind_avg)
gen wealth3 = wealth_ind_avg==0.5 if !mi(wealth_ind_avg)
gen wealth4 = wealth_ind_avg>0.5 if !mi(wealth_ind_avg)

foreach y of varlist cash_postpay{
	gen `y'_w1 = wealth1*`y'
	gen `y'_w2 = wealth2*`y'
	gen `y'_w3 = wealth3*`y'
	gen `y'_w4 = wealth4*`y'	
}
		

reghdfe n_productivity cash_postpay_w1 cash_postpay_w2 cash_postpay_w3 cash_postpay_w4 wealth1 wealth2 wealth3 wealth4 cash_announce blhrprod blhrprodsq blhrprod_miss bs_labor_30_miss future_fin_worry_miss i.pd if pd>0, vce(cl pid) absorb(roundgroup)

cap drop xval_cash* coef_cash* se_cash* uconf_cash* lconf_cash* count_cash*
gen xval_cash1 = _n if _n<5
gen coef_cash1 = .
gen se_cash1 = .
gen count_cash1 = .

forval i=1/4 {
	replace coef_cash1 = _b[cash_postpay_w`i'] if _n==`i' 
	replace se_cash1 = _se[cash_postpay_w`i'] if _n==`i' 
	count if wealth`i'==1 & pid1==1
	replace count_cash1 = r(N)/407 if _n==`i' 
}

gen uconf_cash1 = coef_cash1 + 1.645*se_cash1
gen lconf_cash1 = coef_cash1 - 1.645*se_cash1
gen count_cash2 = 0 if _n<5


twoway (scatter coef_cash1 xval_cash1 , msymbol(S) msize(medium) mcolor("100 149 237") ) ///
       (rcap uconf_cash1 lconf_cash1 xval_cash1, color("100 149 237"))  ///
	   , graphregion(color(white) margin(b+1)) yscale(range(0 0.5) titlegap(*10)) ylabel(#4) yline(0, lpattern(solid) lcolor(gs12) lwidth(medthin)) ytitle("Productivity (SDs)") /// 
	   xscale(range(0.5 4.5) titlegap(*10)) xlabel(1 "0" 2 "0 < i < 0.5" 3 "0.5" 4 "0.5 < i", nogrid) xtitle("Wealth index") legend(off)

graph export "$oa/$f/Figure_A3.eps", replace
graph export "$oa/$f/Figure_A3.png", replace
